#include <iostream>  
#include "intArray_t.h"  
using namespace std; 

int main() {
   int *x;
   int y;
   int ret;
   
   cout << "Please give an initial size for the array:" << endl;
   cin >> y;
   intArray_t arr(y);
   
   while(1) {
   cout <<
    "\n| n | fst | lst | empty | ins | rmv | RmvAll | Append | Prepend | delete | DeleteAll < | : ";

       char c;
       cin >> c;

       if(c!='n' && c!='f' && c!='l' && c!='e' && c!='i'
                 && c!='r' && c!='R' && c!='<'
                 && c!='A' && c!='P' && c!='D' && c!='d' && c!='q') {
    	   cout << "No such command. Try again (q to exit)." << endl;
    	   continue;
       }
       
       if (c == 'q') {
    	   break;
       }

       switch (c) {
		   case 'n' :  cout << arr.getNumberOfElements() << endl;  break;
           case 'f' :  
        	   if (arr.getFirstElement() != 0) {
        		   cout << *arr.getFirstElement() << endl;
        	   } else {
        		   cout << "No first element"  << endl;
        	   }
        	   break;
           case 'l' :  
        	   if (arr.getLastElement() != 0) {
        		   cout << *arr.getLastElement() << endl;
        	   } else {
        		   cout << "No last element"  << endl;
        	   }
        	   break;
           case 'e' :  
        	   cout << (arr.isEmpty() ? "Empty" : "No") << endl;
               break;
           case 'i' :  // insert
        	   x = new int;
        	   cout << "Please enter a number to insert: ";
        	   cin >> *x;
        	   arr.insert(x);
        	   cout << "Inserted "<< *x <<endl; 
               break;
           case 'r' :  // remove
        	   cout << "Please enter a number to remove: ";
        	   cin >> y;
        	   x = arr.remove(y);
        	   if (x != 0) {
        		   cout << "Successfully removed " << *x << endl;
        	   } else {
        		   cout << "Didn't find element " << y << endl;
        	   }
           case 'R' :
        	   arr.removeAll();
        	   cout << "Removed all elements" << endl;
        	   break;
           case 'A' :
        	   x = new int;
        	   cout << "Please enter a number and index to append" << endl;
        	   cin >> *x >> y;
        	   ret = arr.append(y, x);
        	   if (ret == 0) {
        		   cout << "Coulnd't append to index " << y << endl;
        	   } else {
        		   cout << "Successfully appended " << *x << " to index " << y << endl;
        	   }
        	   break;
           case 'P' :
        	   x = new int;
        	   cout << "Please enter a number and index to prepend" << endl;
        	   cin >> *x >> y;
        	   ret = arr.prepend(y, x);
        	   if (ret == 0) {
        		   cout << "Coulnd't prepend to index " << y << endl;
        	   } else {
        		   cout << "Successfully prepended " << *x << " to index " << y << endl;
        	   }
        	   break;
           case 'd' :  // delete
        	   cout << "Please enter a number to delete: ";
        	   cin >> y;
        	   arr.removeDelete(y);
        	   cout << "Successfully removed & deleted all " << y << endl;
        	   break;
           case 'D' : // DeleteAll
        	   arr.removeDeleteAll();
        	   cout << "Removed and deleted all elements" << endl;
        	   break;
           case '<' :
        	   arr.printAll();
        	   break;
       }
   }

   return 0;
}